﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DataProvider;
namespace DalatCooking.Core
{
    class PollAccessor:IPollRepository
    {
        public override int Insert(Poll entity)
        {
            object rs = IDataProvider.Instance.OExecuteNonQuery("@PollID", "Poll_Insert", entity.PollID, entity.Question, entity.Block, entity.IsActive);
            return int.Parse(rs.ToString());   
        }

        public override bool Update(Poll entity)
        {
            int rs = IDataProvider.Instance.ExecuteNonQuery( "Poll_Update", entity.PollID, entity.Question, entity.Block, entity.IsActive);
            return rs > 0;
        }

        public override bool Delete(int pollID)
        {
            return IDataProvider.Instance.ExecuteNonQuery("Poll_delete", pollID) > 0;
        }

        public override List<Poll> FindAll()
        {
            return CBO.FillCollection<Poll>(IDataProvider.Instance.ExecuteReader("Poll_FindAll"));
        }
        public override DataSet FindAllPollRandom()
        {
            return IDataProvider.Instance.ExecuteDataset("Poll_getActive");
        }
        public override DataSet FindAllPoll()
        {
          return  IDataProvider.Instance.ExecuteDataset("Poll_FindAll");
        }

        public override DataSet FindPoll_ByID(int pollID)
        {
            return IDataProvider.Instance.ExecuteDataset("Poll_FindByID", pollID);
        }

        public override int SelectPollIP(int pollID, string ipAddress)
        {
            return IDataProvider.Instance.ExecuteScalar<int>("PollIPs_SelectByID", pollID, ipAddress);
        }

        public override int InsertPollIP(int pollID, string ipAddress)
        {
            return IDataProvider.Instance.ExecuteNonQuery("PollIPs_Insert", pollID, ipAddress);
        }
        public override int InsertChoice(int PollID, string Choice)
        {
            return IDataProvider.Instance.ExecuteNonQuery("PollChoices_insert", PollID, Choice);
        }

        public override int UpdateChoice(int PollChoiceID, string Choice)
        {
            return IDataProvider.Instance.ExecuteNonQuery("PollChoices_update", PollChoiceID, Choice);
        }

        public override int UpdateChoiceVote(int choiceID)
        {
            return IDataProvider.Instance.ExecuteNonQuery("PollChoices_UpdateVote", choiceID);
        }

        public override int DeleteChoice(int choiceID)
        {
            return IDataProvider.Instance.ExecuteNonQuery("PollChoices_delete", choiceID);
        }
    }
}
